// 设计⼀个 Product 接⼝，包含id、name、price等必要属性，以及⼀个可选的description属性。然后
// 创建⼏个符合该接⼝的对象，并编写⼀个函数来计算多个产品的总价。
interface Product {
    id: number;
    name: string;
    price: number;
    description?: string;
}
let product1: Product = {
    id: 1,
    name: "apple",
    price: 10
};

let product2: Product = {
    id: 2,
    name: "banana",
    price: 20,
    description: "This is banana"
};

let product3: Product = {
    id: 3,
    name: "orange",
    price: 30
};

function sum(products: Product[]): number {
    let totalPrice = 0;
    for (let i = 0; i < products.length; i++) {
        totalPrice += products[i].price;
    }
    return totalPrice;
}

console.log(sum([product1, product2, product3]));